package com.example.im.dao;

import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.example.im.entity.ChatRecordLast;

import java.util.List;

@Dao
public interface ChatRecordLastDao {

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    Long insert(ChatRecordLast record);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    void insert(List<ChatRecordLast> records);

    @Update(onConflict = OnConflictStrategy.REPLACE)
    void update(ChatRecordLast record);

    @Delete
    void delete(ChatRecordLast record);


    @Query("DELETE FROM ChatRecordLast")
    void delete();

    @Query("DELETE FROM ChatRecordLast WHERE f_id= :f_id")
    void delete(int f_id);

    @Query("SELECT * FROM ChatRecordLast ORDER BY time DESC")
    List<ChatRecordLast> loadAll();

    @Query("SELECT * FROM ChatRecordLast WHERE f_id= :fromId AND type = :type")
    ChatRecordLast getChatRecordLastByFIdAndType(int fromId, int type);


    @Query("SELECT * FROM ChatRecordLast WHERE f_id= (SELECT id FROM FriendOrRoom WHERE account =:account AND type =:type )")
    ChatRecordLast getChatRecordLast(String account, int type);

    @Query("SELECT * FROM ChatRecordLast WHERE id= :id")
    ChatRecordLast getChatRecordLastByID(int id);


    @Query("SELECT * FROM ChatRecordLast WHERE f_id= :fid")
    ChatRecordLast selectChatRecordLastByFId(int fid);

}
